/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database.dao;

import database.common.GenericDao;
import database.entity.OrderDetails;
import database.entity.Orders;
import database.entity.StockDetails;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author Administrator
 */
public class OrderDetailsDao extends GenericDao<OrderDetails, Integer> {

    public List<OrderDetails> getAllDetailsByStock(StockDetails aThis) {
        Session session = sessionFactory.getCurrentSession();
        session.beginTransaction();
        Criteria c = session.createCriteria(OrderDetails.class);
        c.add(Restrictions.eq("stockDetail", aThis));
        c.createAlias("order", "order_alias").add(Restrictions.disjunction().add(Restrictions.eq("order_alias.status",0)));
        List<OrderDetails> list = c.list();
        session.flush();
        session.getTransaction().commit();
        return list;
    }

    public List<OrderDetails> getAllDetailsByOrder(Orders aThis) {
        Session session = sessionFactory.getCurrentSession();
        session.beginTransaction();
        Criteria c = session.createCriteria(OrderDetails.class);
        c.add(Restrictions.eq("order", aThis));
        List<OrderDetails> list = c.list();
        session.flush();
        session.getTransaction().commit();
        return list;
    }
}
